<template>
  <div class="login">
    <div class="left">
      <div class="login-title">
        <img class="t1" src="@/assets/img/login_logo.png" alt />
        <span class="t2">黑马面面</span>
        <div class="t3"></div>
        <div class="t4">用户登录</div>
      </div>
       
      <!-- 表单
      el-form  :model数组绑定  label-width:标题宽度
          el-form-item  label:标题
        el-input
            v-model:双向绑定
            prefix-icon前面图标
            show-password
    栅栏布局
       el-row  行  24列
          el-col  :span="多少列"
    el-checkbox  v-model:双向绑定  label="选中该项后的值"
         v-model的值为字符串或者boolean值时,它选中某项后它的值为true,取消就为false
         v-model的值为数组 它选中某项后它的值为该数组添加该项,取消就为该数组删除该项 
    el-button  type="primary" 
      -->
      <el-form :model="form" class="form" :rules="rules" ref="form">
        <el-form-item prop="phone">
          <el-input v-model="form.phone" placeholder="请输入手机号" prefix-icon="el-icon-user"></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input
            v-model="form.password"
            placeholder="请输入密码"
            prefix-icon="el-icon-lock"
            show-password
          ></el-input>
        </el-form-item>
        <el-form-item prop="code">
          <el-row>
            <el-col :span="16">
              <el-input v-model="form.code" prefix-icon="el-icon-key" placeholder="请输入验证码"></el-input>
            </el-col>
            <el-col :span="8">
              <img class="login-code" src="@/assets/img/login_code.jpg" alt />
            </el-col>
          </el-row>
        </el-form-item>
        <el-form-item prop="isPass" >
          <el-checkbox v-model="form.isPass"  class="isPass">
            <span>我已阅读并同意</span>
            <el-link type="primary">用户协议</el-link>
            <span>和</span>
            <el-link type="primary">隐私条款</el-link>
          </el-checkbox>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" class="btn" @click="toLogin">登录</el-button>
          <br />
          <el-button type="primary" class="btn" @click="toRegister">注册</el-button>
        </el-form-item>
      </el-form>
    </div>
    <img class="right" src="@/assets/img/login_img.png" alt />
    <register ref="register"></register>
  </div>

</template>
<script>
import register from './register'
export default {
  components:{
    register
  },
  data() {
    return {
      form:{
      phone: "", //	是	string	手机号
      password: "", //	是	string	密码
      code: "", //	是	string	验证码
      isPass: [],
      },
      rules:{
        phone:[{required:true,message:"请输入手机号",trigger:'change'},
               {min:11,max:11,message:"请输入11位手机号",trigger:'change'}
        ],
        password:[
          {required:true,message:"请输入密码",trigger:'change'},
          {min:6,max:12,message:"请输入6-12位密码",trigger:'change'}
        ],
        code:[
          {required:true,message:"请输入验证码",trigger:'change'},
          {min:4,max:4,message:"请输入4位验证码",trigger:'change'}
        ],
        isPass:[{required:true,message:"请勾选协议",trigger:'change'}]
      }
    };
  },
  methods: {
    toLogin(){
      this.$refs.form.validate(result=>{
        if(result){
          this.$message.success('验证通过')
        }else{
          this.$message.error('验证失败')
        }
      })
    },
  toRegister(){
        this.$refs.register.isShow = true    
  }
  },
};
</script>
<style lang="less">
.login {
  height: 100%;
  background: linear-gradient(#1493fa 28%, #01c6fa 96%);
  display: flex;
  align-items: center;
  justify-content: space-around;
  .left {
    width: 478px;
    height: 550px;
    padding: 42px;
    background-color: #f5f5f5;
    .login-title {
      display: flex;
      align-items: center;
      .t1 {
        width: 25px;
        height: 18px;
      }
      .t2 {
        font-size: 24px;
        font-family: SourceHanSansCN Regular, SourceHanSansCN Regular-Regular;
        font-weight: 400;
        text-align: left;
        color: #0c0c0c;
        margin: 0 14px;
      }
      .t3 {
        width: 1px;
        height: 28px;
        background: #c7c7c7;
        margin-right: 12px;
      }
      .t4 {
        font-size: 22px;
        font-family: PingFangSC Regular, PingFangSC Regular-Regular;
        font-weight: 400;
        text-align: left;
        color: #0c0c0c;
      }
    }
    .form {
      margin-top: 30px;
      .login-code{
        width: 100%;
        height: 40px;
      }
      .btn {
        display: block;
        width: 100%;
      }
      .btn:nth-child(2) {
         margin-top: 20px; 
      }
      .isPass {
        display: flex;
        align-items: center;
      }
    }
  }
}
</style>